package com.yd.controller.app;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yd.pojo.Banner;
import com.yd.service.BannerService;
import com.yd.tool.UtsReg;

@Controller
public class BannerControllerApp {
	@Resource
	private BannerService bannerService;
	
	@RequestMapping(value = {"/app/banner/list"})
	@ResponseBody
	public String app_banner_list(HttpServletRequest request) {
		JSONObject jsonObject = new JSONObject();
		
		String tid="";
		String page="";
		String size="";
		
		if(UtsReg.getIntXl(request.getParameter("tid"))){
			tid=request.getParameter("tid").trim();
		}
		if(UtsReg.getIntXl(request.getParameter("page"))){
			page=request.getParameter("page").trim();
		}else{page = "1";}
		if(UtsReg.getIntXl(request.getParameter("size"))){
			size=request.getParameter("size").trim();
		}else{size = "10";}
		
		PageHelper.startPage(Integer.valueOf(page), Integer.valueOf(size));
		List<Banner> list = null;
		EntityWrapper<Banner> ew=new EntityWrapper<Banner>();
		if(tid.length()>0){
			ew.eq("tid", tid);
		}
		list=bannerService.selectList(ew.orderBy("id",false));
		PageInfo<Banner> pages = new PageInfo<Banner>(list);
		
		jsonObject.put("data", pages);
		jsonObject.put("error", "0");
		jsonObject.put("msg", "成功");
		return jsonObject.toString();
	}
	
}
